package com.kangye.enterprise.frontdesk.service.impl;

import com.kangye.enterprise.frontdesk.entity.*;
import com.kangye.enterprise.frontdesk.mapper.BannerMapper;
import com.kangye.enterprise.frontdesk.service.BannerService;
import com.kangye.enterprise.frontdesk.util.RedisStorageUtil;
import com.kangye.enterprise.frontdesk.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @program: enterprise
 * @description: 轮播图实现类
 * @author: 索腾龙
 * @create: 2021-05-27 15:19
 **/
@Service
@Transactional
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerMapper bannerMapper;
    @Autowired
    private RedisStorageUtil redisStorageUtil;
//    //首页“搜索框”（李易衡）
//    @Override
//    public ViewJsonObject<Map<String, Object>> searchBoxItem(String sear) {
//        List<Map<String,Object>> list = bannerMapper.searchBoxItem(sear);
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }else {
//            return new ViewJsonObject<>(1,"操作失败");
//        }
//    }

    //首页“头条轮播图”（李易衡）
    @Override
    public ViewJsonObject<Map<String,Object>> carouselMap(String regionName) {
        List<Map<String,Object>> list = bannerMapper.carouselMap(regionName);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }
    //首页“广告”（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> adver(String regionName) {
        List<Map<String,Object>> list = bannerMapper.adver(regionName);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //首页“看通知、读政策、阅公示”最热（李易衡）
    @Override
    public ViewJsonObject<Map<String,Object>> lookNoticeHot(String sear , Integer circularSynthesis, String regionName, String domoinName, String departmentName, String rankName) {
        List<Map<String,Object>> list = bannerMapper.lookNoticeHot(sear,circularSynthesis,regionName,domoinName,departmentName,rankName);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }
    //首页“看通知、读政策、阅公示”最新（李易衡）
    @Override
    public ViewJsonObject<Map<String,Object>> lookNoticeNew(String sear , Integer circularSynthesis, String regionName, String domoinName, String departmentName, String rankName) {
        List<Map<String,Object>> list = bannerMapper.lookNoticeNew(sear,circularSynthesis,regionName,domoinName,departmentName,rankName);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //项目
    @Override
    public ViewJsonObject<Map<String,Object>> reportItemsHot(String sear,Integer itemObj ,String regionName, String domoinName, String departmentName) {
        List<Map<String,Object>> list = bannerMapper.reportItemsHot(sear,itemObj ,regionName,domoinName,departmentName);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }




//    //首页“看通知”下的通知详情（李易衡）
//    @Override
//    public ViewJsonObject<Map<String,Object>> lookNoticeDetails() {
//        List<Map<String,Object>> list = bannerMapper.lookNoticeDetails();
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }
//        return new ViewJsonObject<>(1,"操作失败");
//    }
//
//    //首页“读政策”（李易衡）
//    @Override
//    public ViewJsonObject<Map<String,Object>> readPolicy(String regionName,String domoinName,String departmentName,String rankName) {
//        List<Map<String,Object>> list = bannerMapper.readPolicy(regionName);
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }
//        return new ViewJsonObject<>(1,"操作失败");
//    }
    //首页“读政策”详情（李易衡）
    @Override
    public List<Circular> readPolicyDetails() {
        List<Circular> list = bannerMapper.readPolicyDetails();
        return list;
    }

//    @Override
//    public ViewJsonObject<Domoin> DomoinBox() {
//        return null;
//    }



//    //首页“报项目”（李易衡）
//    @Override
//    public List<Item> reportItems(String regionName,String domoinName,String departmentName,String rankName) {
//        List<Item> list = bannerMapper.reportItems(regionName);
//        return list;
//    }
//    //首页“报项目”详情（李易衡）
//    @Override
//    public ViewJsonObject<Map<String,Object>> reportItemsDetails() {
//        List<Map<String,Object>> list = bannerMapper.reportItemsDetails();
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }else {
//            return new ViewJsonObject<>(1,"操作失败");
//        }
//    }

    @Override
    public ViewJsonObject<Domoin> domoinBox() {
        List<Domoin> list = bannerMapper.domoinBox();
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }
    @Override
    public ViewJsonObject<Department> departmentBox() {
        List<Department> list = bannerMapper.departmentBox();
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    @Override
    public ViewJsonObject<Rank> rankBox() {
        List<Rank> list = bannerMapper.rankBox();
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }
    //精准配根据企业名查询企业地址
    @Override
    public ViewJsonObject<Map<String,Object>> searchMatches(String matchingCompanyname) {
         List<Map<String,Object>> list = bannerMapper.searchMatches(matchingCompanyname);
//         redisStorageUtil.addObjList("list",list,5, TimeUnit.MINUTES);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }
    //精准配根据地址查询相似的政策
    @Override
    public ViewJsonObject<Map<String,Object>> searchMatch(String regionName) {
        List<Map<String,Object>> list = bannerMapper.searchMatch(regionName);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //即将截止（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> searchMatchEnd(String regionName) {
        List<Map<String,Object>> list = bannerMapper.searchMatchEnd(regionName);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }


    //精准配筛选→产业领域（李易衡）
    @Override
    public ViewJsonObject<Domoin> indufie() {
        List<Domoin> list = bannerMapper.indufie();
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //精准配筛选→政策主题（李易衡）
    @Override
    public ViewJsonObject<Polithem> polithems() {
        List<Polithem> list = bannerMapper.polithems();
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }



//    @Override
//    public ViewJsonObject<Map<String,Object>> searchMatch(Model model) {
//        String string =
//        return null;
//    }


    //首页“阅公示”（李易衡）
//    @Override
//    public List<Publicity> readPubilcize(String regionName) {
//        List<Publicity> list = bannerMapper.readPublicity(regionName);
//        return list;
//    }

    //筛选政策主题（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> subjectAreasess(String regionName,List<String> subjectAreasboxlist) {
        List<Map<String,Object>> list = bannerMapper.subjectAreasess(regionName,subjectAreasboxlist);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //筛选政策产业领域（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> induld(String regionName, List<String> induldboxlist) {
        List<Map<String,Object>> list = bannerMapper.induld(regionName,induldboxlist);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

//    @Override
//    public Integer screnpol(List<Theset> list) {
//        return bannerMapper.screnpol(list);
//    }

//    @Override
//    public ViewJsonObject<Map<String, Object>> screenpol(List<String> screenpolicylist) {
//        List<Map<String,Object>> list = bannerMapper.screenpol(screenpolicylist);
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }else {
//            return new ViewJsonObject<>(1,"操作失败");
//        }
//    }

    @Override
    public void custom(String polithemThemes) {
        bannerMapper.custom(polithemThemes);
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }else {
//            return new ViewJsonObject<>(1,"操作失败");
//        }
    }

    //项目定时推送里的区划设置（李易衡）
    @Override
    public Integer regionaliza(List<Alization> list) {
        return bannerMapper.regionaliza(list);
    }

    //主题设置→政策主题（李易衡）
    @Override
    public void follow(Integer usersid, String thesetName) {
        bannerMapper.follow(usersid,thesetName);
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }else {
//            return new ViewJsonObject<>(1,"操作失败");
//        }
    }


//取消关注
    @Override
    public void cancelAtten(Integer usersid, String thesetName) {
        bannerMapper.cancelAtten(usersid,thesetName);
    }

    //点击帮助与反馈（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> fixedquan(String question) {
        List<Map<String,Object>> list =  bannerMapper.fixedquan(question);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //我要反馈（李易衡）
    @Override
    public void feedback(Integer usersId,String helpfeedbackQuestion, String helpfeedbackEnclosure) {
//        List<Map<String,Object>> list =  bannerMapper.feedback(usersId,helpfeedbackQuestion,helpfeedbackEnclosure);
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }else {
//            return new ViewJsonObject<>(1,"操作失败");
//        }
        bannerMapper.feedback(usersId,helpfeedbackQuestion,helpfeedbackEnclosure);
    }

    //是否解决（李易衡）
    @Override
    public void modifyState(Integer usersId,String helpfeedbackQuestion) {
        bannerMapper.modifyState(usersId,helpfeedbackQuestion);
    }

    //待解决问题展示（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> resolved(Integer usersId) {
        List<Map<String,Object>> list =  bannerMapper.resolved(usersId);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //已解决问题展示（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> resolv(Integer usersId) {
        List<Map<String,Object>> list =  bannerMapper.resolv(usersId);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //问题详情（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> quedetails(String helpfeedbackQuestion, Integer usersId) {
        List<Map<String,Object>> list =  bannerMapper.quedetails(helpfeedbackQuestion,usersId);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //我的关注（李易衡）
    //专题
    //政策
    @Override
    public ViewJsonObject<Map<String, Object>> dispol(Integer gzcircularRolees,String usersId) {
        List<Map<String,Object>> list =  bannerMapper.dispol(gzcircularRolees,usersId);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //删除关注（李易衡）
    @Override
    public Integer deldispol(List<Gzcircular> list) {
        return bannerMapper.deldispol(list);
    }

    //我的消息（李易衡）
    @Override
    public ViewJsonObject<Map<String, Object>> myNews(Integer usersId) {
        List<Map<String,Object>> list =  bannerMapper.myNews(usersId);
        if (list.size()>0){
            return new ViewJsonObject<>(list);
        }else {
            return new ViewJsonObject<>(1,"操作失败");
        }
    }

    //注册（李易衡）
    @Override
    public ViewJsonObject<Users> registerUser(Users user) {
        Pattern phone = null;
        Matcher mphone = null;
        boolean bphone = false;
        phone = Pattern.compile("/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$/"); // 验证手机号
        mphone = phone.matcher(user.getUsersPhone());
        bphone = mphone.matches();
        if (bphone=true){
            Pattern name = null;
            Matcher mname = null;
            boolean bname = false;
            name = Pattern.compile("/^[\\u4e00-\\u9fa5]{2,4}$/"); // 姓名
            mname = name.matcher(user.getUsersPhone());
            bname = mname.matches();
            if (bphone=true){
                if(user.getUsersPassword().length()>10&&user.getUsersPassword().length()<6){
                    Integer integer = bannerMapper.registerUser(user);
                    if(integer > 0){
                        return new ViewJsonObject<>(0,"添加成功");
                    }else{
                        return new ViewJsonObject<>(3,"添加失败,请稍后重试");
                    }
                }
            }
        }
        return null;
//        Integer integer = bannerMapper.registerUser(user);
//        if(integer > 0){
//            return new ViewJsonObject<>(0,"添加成功");
//        }else{
//            return new ViewJsonObject<>(1,"添加失败,请稍后重试");
//        }
    }

    @Override
    public ViewJsonObject<Map<String, Object>> checking(String userUsername) {
        List<Map<String,Object>> list =  bannerMapper.checking(userUsername);
        if (list.size()>0){
            return new ViewJsonObject<>(0,"重名");
        }else {

            return new ViewJsonObject<>(list);
        }
    }

    @Override
    public ViewJsonObject<Map<String, Object>> head() {
        List<Map<String,Object>> list =  bannerMapper.head();
        if (list.size()>0){
            return new ViewJsonObject<>(0,"重名");
        }else {

            return new ViewJsonObject<>(list);
        }
    }

//    @Override
//    public Integer checking(String userUsername) {
//        return bannerMapper.checking(userUsername);
//    }

//    @Override
//    public void deldispol(Integer gzcircularRolees, Integer usersId, Integer gzcircularId) {
//        bannerMapper.deldispol(gzcircularRolees,usersId,gzcircularId);
//    }

//    @Override
//    public ViewJsonObject<Map<String, Object>> regionaliza(String[] regionalization, Integer usersId) {
//        List<Map<String,Object>> list= (List<Map<String, Object>>) new HashMap<String,Object>();
//        for (int i =0;i<regionalization.length;i++){
//            System.out.println(regionalization[i]);
//            list = bannerMapper.regionaliza(regionalization[i],usersId);
//        }
//
//
//        System.out.println("service="+usersId);
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }else {
//            return new ViewJsonObject<>(1,"操作失败");
//        }
//    }

//    @Override
//    public ViewJsonObject<Map<String, Object>> regionaliza(List<String> regionalizationlist,Integer usersId) {
//        List<Map<String,Object>> list = bannerMapper.regionaliza(regionalizationlist,usersId);
//        System.out.println("service="+usersId);
//        if (list.size()>0){
//            return new ViewJsonObject<>(list);
//        }else {
//            return new ViewJsonObject<>(1,"操作失败");
//        }
//    }
}